<?php
namespace Admin\Controller;
use Think\Controller;
use Think\Page;
class SystemController extends AuthController {
	/**
	 * 显示列表
	 */
	public function showList(){
		$action = I('action');
		$info = M($action);
		$list = $info->order(array('id'=>'asc'))->select();
		$this->assign('list',$list);
		$this->display($action);
	}
	/**
	 * 获取列表
	 */
	public function getList(){
		$action = I('action');
		$info = M($action);
		$list = $info->order(array('id'=>'asc'))->select();
		$json['data'] = $list;
		$this->ajaxReturn($json);
	}
	/**
	 * 获取信息
	 */
	public function getInfo(){
		$action = I('action');
		$where['id'] = I('id');
		$result = M($action)->where($where)->find();
		$this->ajaxReturn($result);
	}
	/**
	 * 修改信息
	 */
	public function updateInfo(){
		$action = I('action');
		$data = $_POST;
		$where['id'] = I('id');
		$result = M($action)->where($where)->save($data);
		$this->ajaxReturn($result);
	}
	/**
	 * 删除信息
	 */
	public function deleteInfo(){
		$action = I('action');
		$where['id'] = I('id');
		$result = M($action)->where($where)->delete();
		$this->ajaxReturn($result);
	}
	/**
	 * 获取食物类型
	 */
	public function getFoodType(){
		$type = M("FoodType")->field("type_name")->select();
		$this->ajaxReturn($type);
	}
	/**
	 * 添加信息
	 */
	public function addInfo(){
		$action = I('action');
		$data = $_POST;
		$info = M($action);
		$result = $info->add($data);
		if($result){
			$this->success('添加成功','showList/action/'.$action);
		}else{
			$this->error('添加失败');
		}
	}
}